import paho.mqtt.client as mqtt

homename = "m14.cloudmqtt.com"
port = 13536
user = "xxxx"
user_password = "xxxx"

def on_connect(client, obj, flags, rc):
    print("rc: " + str(rc))
    client.subscribe("#")


def on_message(client, userdata, message):
    print("message {} at {}".format(str(message.payload.decode("utf-8")),  message.topic))

client = mqtt.Client("all")
client.on_connect = on_connect
client.on_message = on_message
client.username_pw_set(user, user_password)

print("connecting")
client.connect(homename, port)

client.loop_forever()
